
//
// 120718 - AH - (Midtun) Created.
//

package org.soekrat.environment.event;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *   Holds
 *   {@link SensorListener}s and publishes events.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC)
 */
public class SensorListeners 
{
  private transient List<SensorListener> m_listeners=
    new ArrayList<SensorListener>();
  
  /**
   * <p>
   *   Constructor.
   * </p>
   */
  public SensorListeners(){}
  
  /**
   * <p>
   *   Adds
   *   {@link SensorListener}.
   * </p>
   * @param l Listener to add.
   */
  public final synchronized void addSensorListener(SensorListener l)
  {
    if (l==null)
    {
      throw new NullPointerException("l");
    }
    
    if (m_listeners==null) m_listeners=new ArrayList<SensorListener>();
    if (!m_listeners.contains(l)) m_listeners.add(l);
  }
  
  /**
   * <p>
   *   Removes
   *   {@link SensorListener}.
   * </p>
   * @param l Listener to remove.
   */
  public final synchronized void removeSensorListener(SensorListener l)
  {
    if (l==null)
    {
      throw new NullPointerException("l");
    }
    
    if (m_listeners==null) m_listeners=new ArrayList<SensorListener>();
    if (!m_listeners.contains(l)) m_listeners.add(l);
  }
  
  /**
   * <p>
   *   Invoke
   *   {@link SensorListener#sensed(SensorEvent)}.
   * </p>
   * @param e Event to published.
   */
  /*
  public final void fireSensed(SensorEvent e)
  {
    if (e==null)
    {
      throw new NullPointerException("e");
    }
    
    if (m_listeners==null) return;
    
    SensorListener[] l=SensorListener.EMPTY_ARRAY;
    synchronized(this){ l=m_listeners.toArray(l); }
    for (SensorListener curr : l) curr.sensed(e);
  }
  */
  
}
